#include "physicsManager2d.h"

using namespace ePhys;

physicsManager2d::physicsManager2d(void)
{
}

physicsManager2d::~physicsManager2d(void)
{
	drop();	
}

void physicsManager2d::drop(void) {
	objs.startIter();
	obj2d *o = objs.next();
	while(o) {
		delete o;		
		o = objs.next();
	}	
	objs.empty();
}

obj2d *physicsManager2d::pick(vec2d p) {
	obj2d *closest = 0;
	f32 dist = -1.f;

	objs.startIter();
	obj2d *o = objs.next();
	while(o) {
		bool isInside = false;

		if(o->isInside(p)) {
			f32 tDist = o->center.distTo(p);
			if(tDist > dist || dist == -1.f) {
				dist = tDist;
				closest = o;
			}
		}
		o = objs.next();
	}
	return closest;
}